<!--
  Copyright (c) 2020 classmate-sun
  [Software Name] is licensed under Mulan PSL v2.
  You can use this software according to the terms and conditions of the Mulan PSL v2.
  You may obtain a copy of Mulan PSL v2 at:
          http://license.coscl.org.cn/MulanPSL2
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  See the Mulan PSL v2 for more details.
-->

<template>
  <div class="Home">
    <!--背景图-->
    <div class="bg" :style="{ height: bgHeight + 'px' }">
      <div class="bg-content loading">
        <h1>什 么 是 快 乐</h1>
        <h2>格物致知，一种简单的快乐</h2>
        <div style="margin-top: 50px;margin-bottom: 20px">
          <el-row>
            <el-col :span="2" offset="8" >
              <div style="font-size: 18px" class="extItem" @click="gotoCSDN()">
                <img src="./csdn2.png" alt="" height="40"> CSDN
              </div>
            </el-col>
            <el-col :span="2">
              <div style="font-size: 18px" class="extItem" @click="gotoGitHub()">
                <img src="./github.png" alt="" height="40"> Github
              </div>
            </el-col>
            <el-col :span="2">
              <div style="font-size: 18px" class="extItem" @click="gotoGitee()">
                <img src="./gitee.svg" alt="" height="40"> Gitee
              </div>
            </el-col>
            <el-col :span="2">
              <div style="font-size: 18px" class="extItem" @click="gotoBokeyuan()">
                <img src="./博客园logo.svg" alt="" height="40"> 博客园
              </div>
            </el-col>
          </el-row>
        </div>
        <router-link to="/blog/0">进入本站</router-link>
      </div>
      <i class="bg-icon el-icon-arrow-down"></i>
    </div>

    <!--右上角菜单-->
    <div :class="['menu', { click: ifClick }]">
      <div class="btn" @click="handleClick">
        <span></span>
        <span></span>
        <span></span>
      </div>
      <div :class="['cover', { showclick: !ifClick }]">
        <div class="point">
          <router-link to="/">首页</router-link>
          <router-link to="/blog/0">博客</router-link>
          <router-link to="/message">留言</router-link>
        </div>
        <div class="cover-logo">li jie</div>
      </div>
    </div>

    <!--热门文章-->
    <div class="hot">
      <div class="hot-main">
        <div class="text loading">
          <h2>热门文章</h2>
          <p>
            很想给你写封信,告诉你这里的天气.
            <br />昨夜的那场电影,还有我的心情.
          </p>
        </div>
        <ul class="loading">
          <li v-for="item in articleHotList" :key="item.id ">
            <div class="img">
              <div
                class="bgImg"
                :style="{ backgroundImage: 'url(' + img[Math.floor(Math.random()*10)]+ ')' }"
              ></div>
              <div class="link">
                <a href="javascript:void(0);" @click="gotoarticle(item.id)">
                  <i class="el-icon-link"></i>
                </a>
              </div>
            </div>
            <div class="info">
              <div class="title">
                <a href="javascript:void(0);" @click="gotoarticle(item.id)">{{
                  item.title
                }}</a>
              </div>
              <div class="time">
                {{ item.createTime | year }}年{{ item.createTime | month }}月{{
                  item.createTime | date
                }}日
              </div>
              <div class="content">{{ item.blogText | contentToText }}</div>
              <router-link :to="'/Article/' + item._id">阅读更多</router-link>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <!--网站一访问-->
    <div class="webVisits">
      <div class="bottom">
        <p>网站浏览量：{{webSiteVisit}}</p>
      </div>
    </div>
    <!--关于&友链-->
    <div class="about">
      <div class="wrap">
        <ul class="loading">
          <li>
            <router-link to="/about">关于</router-link>
          </li>
          <li>
            <router-link to="/links">+友情链接</router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="end">
      <div class="bottom">
        <p>Copyright © 2021-2023 LJ 李杰 版权所有</p>
        <a
          target="_blank"
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=32011502012264"
        >
          <img
            src="../../assets/img/police.png"
            style="float: left; margin-right: 3px; height: 17px"
          />苏公网安备32011502012264号
        </a>
        <a
          class="iconfont iconbeian"
          target="_blank"
          href="https://beian.miit.gov.cn/"
          rel="external nofollow"
          >苏ICP备2021051709号-1</a
        >
      </div>
    </div>

    <Denglong v-if="festival.chunjie"></Denglong>
    <Guoqing v-if="festival.guoqingjie"></Guoqing>
  </div>
</template>

<script>
import request from "../../api/index";
import Denglong from "../../components/festival/denglong";
import Guoqing from "../../components/festival/guoqing";

const getArticleHot = request.getArticleHot;

//得到DOM距离页面顶部的距离
function getTop(node) {
  let top = 0;
  while (node !== document.body) {
    top += node.offsetTop;
    node = node.offsetParent;
  }
  return top;
}

export default {
  name: "Home",
  components: {
    Denglong,
    Guoqing,
  },
  data() {
    return {
      bgHeight: 0,
      ifClick: false,
      articleHotList: [],
      festival: {
        chunjie: false,
        qingrenjie: false,
        funvjie: false,
        zhishujie: false,
        yurenjie: false,
        qingmingjie: false,
        laodongjie: false,
        qingnianjie: false,
        ertongjie: false,
        jiandangjie: false,
        jianjunjie: false,
        zhongyuanjie: false,
        jiaoshijie: false,
        zhongqiujie: false,
        guoqingjie: false,
        shengdanjie: false,
      },
      img: [
          'https://cn.bing.com/th?id=OHR.FoxDovrefjell_ZH-CN9554491452_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
          'https://cn.bing.com/th?id=OHR.PicoVolcano_ZH-CN6865997792_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
          'https://cn.bing.com/th?id=OHR.BirdcountAllen_ZH-CN4029022734_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
          'https://cn.bing.com/th?id=OHR.Lichun2023_ZH-CN7842399047_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
          'https://cn.bing.com/th?id=OHR.BabblingBrook_ZH-CN9371346787_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
          'https://cn.bing.com/th?id=OHR.RichmondParkDuck_ZH-CN4956127005_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
          'https://cn.bing.com/th?id=OHR.WaimeaRainbow_ZH-CN1127225170_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
          'https://cn.bing.com/th?id=OHR.CyprusMaze_ZH-CN9448060895_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
          'https://cn.bing.com/th?id=OHR.LionessesNap_ZH-CN9240393299_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
          'https://cn.bing.com/th?id=OHR.SouthDownsSheep_ZH-CN8986424729_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
          'https://cn.bing.com/th?id=OHR.PurpleCrocus_ZH-CN0891528297_1920x1080.jpg&rf=LaDigue_1920x1080.jpg',
      ],
      webSiteVisit:"",
    };
  },

  methods: {
    //设置bg高度与window高度一致
    getWindowHeight() {
      this.bgHeight = window.innerHeight;
    },
    showCover() {
      this.cover = !this.cover;
    },
    //滚轮滚动事件
    handleScroll() {
      let loadingDom = document.querySelectorAll(".loading");
      let scrollTop = document.documentElement.scrollTop + window.innerHeight;
      loadingDom.forEach((node) => {
        if (scrollTop > getTop(node) + 100) {
          node.classList.remove("loading");
        }
      });
    },

    //点击右侧菜单
    handleClick() {
      this.ifClick = !this.ifClick;
    },
    gotoarticle(id) {
      this.$router.push(`/Article/${id}`);
    },
    //
    gotoCSDN(){
      window.location.href = 'https://blog.csdn.net/weixin_43887870?spm=1000.2115.3001.5343'
    },
    gotoGitee(){
      window.location.href = 'https://gitee.com/blackjie_1'
    },
    gotoBokeyuan(){
      window.location.href = 'https://www.cnblogs.com/lijie-helloworld/'
    },
    gotoGitHub(){
      window.location.href = 'https://github.com/AAwonderful'
    },
    getArticleHot(){
      this.$ajax.post(this.$config.url+`/ljblog/blog/hotBlog`).then((res) => {
        console.log(res.data.data);
        this.articleHotList = res.data.data;
      })
    },
    getWebSiteVisit(){
      this.$ajax.get(`${this.$config.url}/common/AddWebSiteVisits`).then((res) => {
        if(res.data.status===this.$config.request_code_success){
          this.webSiteVisit = res.data.data;
        }
      })
    }
  },
  filters: {
    contentToText(value) {
      var div = document.createElement("div");
      div.innerHTML = value;
      return div.innerText;
    },
    date(value) {
      return value.match(/^(\d{4})-(\d{1,2})-(\d{1,2})/)[3];
    },
    month(value) {
      return value.match(/^(\d{4})-(\d{1,2})-(\d{1,2})/)[2];
    },
    year(value) {
      return value.match(/^(\d{4})-(\d{1,2})-(\d{1,2})/)[1];
    },
  },
  created() {
    this.getWindowHeight();
  },
  mounted() {
    this.getArticleHot()
    this.getWebSiteVisit()
    //resize

    window.addEventListener("resize", this.getWindowHeight);

    //scroll
    this.handleScroll();
    window.addEventListener("scroll", this.handleScroll);
    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();

    if (
      (year === 2022 && month === 1 && day >= 25 && day <= 31) ||
      (year === 2022 && month === 2 && day >= 1 && day <= 15)
    ) {
      this.festival.chunjie = true;
    }
    if (
      (month === 2 && day === 14) ||
      (year === 2021 && month === 8 && day === 14) ||
      (year === 2022 && month === 8 && day === 4)
    ) {
      this.festival.qingrenjie = true;
    }
    if (month === 3 && day === 8) {
      this.festival.funvjie = true;
    }
    if (month === 3 && day === 12) {
      this.festival.zhishujie = true;
    }
    if (month === 4 && day === 1) {
      this.festival.yurenjie = true;
    }
    if (month === 4 && day === 5) {
      this.festival.qingmingjie = true;
    }
    if (month === 5 && day === 1) {
      this.festival.laodongjie = true;
    }
    if (month === 5 && day === 4) {
      this.festival.qingnianjie = true;
    }
    if (month === 6 && day === 1) {
      this.festival.ertongjie = true;
    }
    if (month === 7 && day === 1) {
      this.festival.jiandangjie = true;
    }
    if (month === 8 && day === 1) {
      this.festival.jianjunjie = true;
    }
    if (
      (year === 2021 && month === 8 && day === 22) ||
      (year === 2022 && month === 8 && day === 12)
    ) {
      this.festival.zhongyuanjie = true;
    }
    if (month === 9 && day === 10) {
      this.festival.jiaoshijie = true;
    }
    if (
      (year === 2021 && month === 9 && day === 21) ||
      (year === 2022 && month === 9 && day === 10)
    ) {
      this.festival.zhongqiujie = true;
    }
    if ((month === 10 && day >= 1 && day <= 7) || (month === 9 && day === 30)) {
      this.festival.guoqingjie = true;
    }
    if (month === 12 && day >= 24 && day <= 25) {
      this.festival.shengdanjie = true;
    }
  },
  destroyed() {
    window.removeEventListener("resize", this.getWindowHeight);
  },
};
</script>

<style lang="less" scoped>
.Home {
  user-select: none;
  .bg {
    position: relative;
    z-index: 9;
    width: 100%;
    background: url("preview.jpg") center center/cover;
    &::before {
      position: absolute;
      content: "";
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.3);
    }
    .bg-content {
      position: absolute;
      top: 0;
      bottom: 0;
      margin: auto;
      z-index: 1;
      width: 100%;
      height: 254px;
      /*background-color: pink;*/
      text-align: center;
      font-size: 14px;
      line-height: 24px;
      color: white;
      transform: scale(1);
      transition: transform 1s;
      .extItem {

        display: inline-block;
        height: 38px;
        padding: 0 18px;
        color: white;
        white-space: nowrap;
        text-align: center;
        font-size: 14px;
        border: none;
        cursor: pointer;
        margin-top: 20px;
        transition: background-color 0.7s;
        border-radius: 10px;
        &:hover {
          background-color: #bce0e5;
        }
      }
      &.loading {
        transform: scale(0.5);
      }
      h1 {
        font-weight: 400;
        font-size: 2em;
      }
      h2 {
        font-weight: 400;
        letter-spacing: 10px;
        margin: 20px 0;
        font-size: 1em;
      }
      a {
        display: inline-block;
        height: 38px;
        line-height: 38px;
        padding: 0 18px;
        background-color: #bce0e5;
        color: #000;
        white-space: nowrap;
        text-align: center;
        font-size: 14px;
        border: none;
        border-radius: 2px;
        cursor: pointer;
        margin-top: 20px;
        transition: opacity 0.3s;
        border-radius: 10px;
        &:hover {
          opacity: 0.8;
        }
      }
    }
    .bg-icon {
      position: absolute;
      z-index: 11;
      bottom: 30px;
      left: 50%;
      margin-left: -25px;
      width: 50px;
      height: 50px;
      color: #fff;
      font-weight: 700;
      font-size: 36px;
      border-radius: 50%;
      transition: background-color 0.7s;
      line-height: 50px;
      text-align: center;
      cursor: pointer;
      &:hover {
        background-color: #6bc30d;
      }
    }
  }
  .menu {
    .btn {
      box-sizing: border-box;
      position: fixed;
      z-index: 999;
      right: 55px;
      top: 40px;
      padding-top: 12px;
      width: 40px;
      height: 40px;
      cursor: pointer;
      border-radius: 50%;
      background-color: transparent;
      transition: background-color 0.3s;
      &:hover {
        background-color: #6bc30d;
      }
      span {
        position: relative;
        top: 0;
        display: block;
        width: 26px;
        height: 2px;
        margin: 0 auto 5px;
        background-color: #fff;
        transition: all 0.32s;
        transform: rotate(0deg);
      }
    }
    .cover {
      opacity: 0;
      z-index: 8;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.5);
      transition: opacity 0.3s;
      &::before {
        position: absolute;
        left: 100%;
        top: 0;
        content: "";
        width: 4999px;
        height: 100%;
        background-color: #f9f9f8;
        transform: skew(-12deg);
        transition: left 0.3s;
      }
      .point {
        position: absolute;
        right: 0;
        top: 200px;
        z-index: 101;
        font-size: 20px;
        a {
          position: relative;
          display: block;
          text-align: right;
          color: #686967;
          line-height: 46px;
          padding: 10px 30px;
          margin-right: 20px;
          font-size: 20px;
          text-decoration: none;
          -webkit-transition: color 0.6s linear;
          transition: color 0.6s linear;
          &::before {
            position: absolute;
            top: 50%;
            left: 0;
            width: 0;
            opacity: 0;
            height: 1px;
            background-color: #6bc30d;
            content: "";
            transition: all 0.3s;
          }
          &:hover {
            color: #6bc30d;
          }
          &:hover::before {
            width: 100%;
            opacity: 1;
          }
        }
      }
      .cover-logo {
        font-size: 50px;
        position: absolute;
        right: 0;
        bottom: 0;
        z-index: 101;
        padding: 10px 50px;
        font-family: FZJianQRTJW;
        color: #686967;
        cursor: pointer;
      }
    }
    &.click {
      .btn {
        background-color: rgba(0, 0, 0, 0.1);
        span:nth-child(1) {
          top: 8px;
          transform: rotate(45deg);
        }
        span:nth-child(2) {
          top: 1px;
          transform: rotate(-45deg);
        }
        span:nth-child(3) {
          display: none;
        }
      }
      .cover {
        opacity: 1;
        z-index: 10;
        &::before {
          left: 65%;
        }
      }
    }
  }
  .hot {
    overflow: hidden;
    width: 100%;
    position: relative;
    z-index: 9;
    padding: 100px 0;
    background-color: #fff;
    .hot-main {
      max-width: 1170px;
      width: 100%;
      margin: 0 auto;
      text-align: center;
      .text {
        position: relative;
        top: 0;
        opacity: 1;
        transition: opacity 0.3s, top 0.5s;
        &.loading {
          top: -100px;
          opacity: 0;
        }
        > h2 {
          position: relative;
          font-size: 32px;
          padding-bottom: 30px;
          font-weight: 500;
          &::before {
            position: absolute;
            width: 50px;
            height: 2px;
            content: "";
            left: 50%;
            margin-left: -25px;
            bottom: -1px;
            background: #00c2ff;
          }
        }
        > p {
          margin-top: 20px;
          line-height: 22px;
          color: #888;
        }
      }
      > ul {
        display: flex;
        width: 100%;
        height: 503px;
        margin-top: 50px;
        li {
          position: relative;
          top: 0;
          flex: 1;
          width: 33.3%;
          height: 503px;
          padding: 0 10px;
          opacity: 1;
          .img {
            overflow: hidden;
            position: relative;
            width: 100%;
            height: 244px;
            .bgImg {
              width: 100%;
              height: 100%;
              background-position: center center;
              background-size: cover;
            }
            .link {
              position: absolute;
              top: -100%;
              left: 0;
              width: 100%;
              height: 100%;
              background-color: rgba(255, 255, 255, 0.3);
              opacity: 0;
              transition: 0.3s;
              a {
                position: absolute;
                left: 50%;
                top: 50%;
                margin-top: -20px;
                margin-left: -20px;
                width: 40px;
                height: 40px;
                background: #333;
                color: #fff;
                line-height: 40px;
                text-align: center;
                i {
                  font-size: 16px;
                }
              }
            }
            &:hover .link {
              top: 0;
              opacity: 1;
            }
          }
          .info {
            box-sizing: border-box;
            width: 100%;
            height: 209px;
            padding: 30px 15px;
            background: #faf9f9;
            text-align: left;
            .title {
              margin-bottom: 10px;
              text-overflow: ellipsis;
              overflow: hidden;
              white-space: nowrap;
              a {
                color: #333;
                &:hover {
                  color: #777;
                }
              }
            }
            .time {
              color: #bbb;
              font-size: 12px;
              margin-bottom: 15px;
            }
            .content {
              overflow: hidden;
              line-height: 20px;
              height: 60px;
              color: #999;
            }
            .link {
              display: inline-block;
              margin-top: 15px;
              padding: 0;
              background: 0 0;
              border: none;
              color: #29b6f6;
              transition: all 0.4s ease;
              &:hover {
                color: #333;
              }
            }
          }
        }
        li:nth-child(1) {
          transition: 0.6s 0s;
        }
        li:nth-child(2) {
          transition: 0.6s 0.1s;
        }
        li:nth-child(3) {
          transition: 0.6s 0.2s;
        }
        &.loading li {
          top: 100px;
          opacity: 0;
        }
      }
    }
  }
  .webVisits {
    background-color: rgba(0, 0, 0, 0.5);
    .bottom {
      padding: 10px 0;
      text-align: center;
      font-size: 18px;
    }

     .bottom a,
     .bottom p {
      display: block;
       font-size: 17px;
      font-weight: 500;
      text-decoration: none;
      color: #FFFFFF;
    }

     .bottom a {
      display: inline-block;
      margin: 0 5px;
      transition: 0.3s;
    }

    .bottom a:hover {
      color: rgb(71, 147, 150);
    }
  }
  .about {
    position: relative;
    z-index: 9;
    width: 100%;
    height: 48px;
    padding: 33px 0 64px;
    margin: 0 auto;
    &::after {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      z-index: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.5);
    }
    ul {
      position: relative;
      z-index: 9;
      width: 425px;
      margin: 0 auto;
      opacity: 1;
      transition: 0.6s;
      &.loading {
        width: 1000px;
        opacity: 0;
      }
      li {
        position: relative;
        width: 198px;
        height: 46px;
        border: 1px solid #fff;
        &:nth-child(1) {
          float: left;
        }
        &:nth-child(2) {
          float: right;
        }
        &::after {
          position: absolute;
          left: 0;
          top: 0;
          content: "";
          width: 0;
          height: 46px;
          background-color: #b3d1c7;
          transition: width 0.5s;
        }
        &:hover::after {
          width: 100%;
        }
        a {
          position: relative;
          z-index: 1;
          display: block;
          width: 100%;
          height: 100%;
          line-height: 46px;
          text-align: center;
          color: #fff;
        }
      }
    }
  }
  .end {
    position: relative;
    z-index: 9;
    background-color: rgba(0, 0, 0, 0.5);
  }
  .end .bottom {
    padding: 10px 0;
    text-align: center;
    font-size: 13px;
  }

  .end .bottom a,
  .end .bottom p {
    display: block;
    line-height: 17px;
    text-decoration: none;
    color: #ccc;
  }

  .end .bottom a {
    display: inline-block;
    margin: 0 5px;
    transition: 0.3s;
  }

  .end .bottom a:hover {
    color: rgb(71, 147, 150);
  }
}
</style>










